package com.inhim.pjhim.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.inhim.pjhim.app.MyApplication;
import com.inhim.pjhim.entity.ProjectListEntity;
import com.inhim.pjhim.myinterface.IMusic;

import java.util.List;

import fm.jiecao.jcvideoplayer_lib.JCRadioPlayerStandard;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

public class Mp3Receiver extends BroadcastReceiver {
    private MyApplication application;
    private int songItemPos;
    private JCRadioPlayerStandard mJcVideoPlayerStandard;
    private List<ProjectListEntity.List> projectListEntitys;

    @Override
    public void onReceive(Context context, Intent intent) {

        application = (MyApplication) context.getApplicationContext();
        mJcVideoPlayerStandard = application.getJCRadioPlayerStandard();
        projectListEntitys = application.getProjectListEntitys();
        songItemPos = application.getSongItemPos();
        String ctrl_code = intent.getAction();//获取action标记，用户区分点击事件

        //music = application.music;//获取全局播放控制对象，该对象已在Activity中初始化
        if ("play".equals(ctrl_code)) {
            playRadio(songItemPos);
            System.out.println("play");
        } else if ("pause".equals(ctrl_code)) {
            mJcVideoPlayerStandard.pauseRadio();
            System.out.println("pause");
        } else if ("next".equals(ctrl_code)) {
            playRadio(++songItemPos);
            System.out.println("next");
        } else if ("last".equals(ctrl_code)) {
            playRadio(--songItemPos);
            System.out.println("last");
        }

        if ("cancel".equals(ctrl_code)) {
            //application.notManager.cancel(Const.NOTI_CTRL_ID);
            System.exit(0);
        }
    }

    private void playRadio(int position) {
        mJcVideoPlayerStandard.setUp(projectListEntitys.get(position).getUrl()
                , JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, position);
        try {
            //if(JCMediaManager.instance().mediaPlayer.isPlaying() && JCMediaManager.instance().CURRENT_PLAYING_URL.equals(videoUrl)){
            //mJcVideoPlayerStandard.setIconStatus();
            mJcVideoPlayerStandard.playRadio();
            //PrefUtils.putBoolean(isPlayingKey,false);
            //PrefUtils.putString(isPlayingUrl,"");
            //}
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
